package com.wc.alorithm_blue_bridge_history.littlewhite.Q231227.Q10015;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2023/12/27 19:26
 * 蓝桥圣诞树
 * https://www.lanqiao.cn/problems/10015/learning/?contest_id=157
 * @description
 */
public class Main {
    static int maxN = 30 + 10;
    // 每个点的下一个点
    static int[][] edge;
    // 每个点的颜色
    static char[] color;
    // 每个点连的边数
    static int[] idxC;
    static FastReader in = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    // 标记答案
    static boolean flg;

    public static void main(String[] args) {
        int t = in.nextInt();
        while (t-- > 0) {
            edge = new int[maxN][3];
            color = new char[maxN];
            idxC = new int[maxN];
            int n = in.nextInt();
            String colors = in.next();

            flg = false;
            for (int i = 0; i < n; i++) {
                color[i + 1] = colors.charAt(i);
            }

            for (int i = 1; i < n; i++) {
                int u = in.nextInt();
                int v = in.nextInt();
                edge[u][idxC[u]++] = v;
                edge[v][idxC[v]++] = u;
            }
            int root = 0;

            // 找一个顶点度为1的点
            for (int i = 1; i <= n; i++) {
                if (idxC[i] == 1) {
                    root = i;
                    break;
                }
            }
            // 从这个点开始便利
            search(root, edge[root][0], 1);
            out.println(flg ? "NO" : "YES");
        }
        out.flush();
    }

    public static void search(int u, int v, int step) {
        if (flg) {
            return;
        }
        // 当遇到分叉路口的时候，要先判断分岔路
        if (idxC[v] == 3) {
            int same = 1;
            for (int i = 0; i < 3; i++) {
                if (color[edge[v][i]] != u && color[v] == color[edge[v][i]]) {
                    same++;
                }
            }
            if (same == 3) {
                flg = true;
                return;
            }
        }
        // 颜色相同就+1；
        if (color[v] == color[u]) {
            step++;
            if (step == 3) {
                flg = true;
                return;
            }
            for (int i = 0; i < idxC[v]; i++) {
                if (edge[v][i] != u) {
                    search(v, edge[v][i], step);
                }
            }
        } else {
            // 不同就统计，重新开始
            for (int i = 0; i < idxC[v]; i++) {
                if (edge[v][i] != u) {
                    search(v, edge[v][i], 1);
                }
            }
        }
    }

}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }
}
